package com.work.test;

import java.util.Scanner;

public class T6 {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int length=sc.nextInt();
        int[] arr=new int[length+1];
        int n=sc.nextInt();
        int start,end;
        int flag=0;
        for (int i=0;i<n;i++){
            start=sc.nextInt();
            end=sc.nextInt();
            arr[start]++;
            arr[end]--;
        }
        int count=0;
        for (int i=0;i<arr.length;i++){
           if (arr[i]!=0){
               flag+=arr[i];
               continue;
           }
           if (flag==0)
               count++;
        }
        System.out.println(count);
    }
}
